package com.jettech.oa.domain;

import java.io.Serializable;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.OrderBy;
import javax.persistence.Table;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;

/**
 * 角色
 * @author Administrator
 *
 */
@Entity
@Table(name="jettech_role")
public class Role implements Serializable {
	private static final long serialVersionUID = 4101982229576066735L;
	private Long id;//主键
	private List<Resource> resources;//拥有的资源列表
	private String name;//角色名称
	private String code;//角色编码
	private String desc;//描述
	private String status;//状态
	
	public Role(){
		
	}
	@Id
	@GeneratedValue(strategy=GenerationType.AUTO)
	@Column(name="role_id")
	public Long getId() {
		return id;
	}
	public void setId(Long id) {
		this.id = id;
	}
	@ManyToMany
	@JoinTable(name = "jettech_role_resource", joinColumns = { @JoinColumn(name = "role_id") }, inverseJoinColumns = { @JoinColumn(name = "resource_id") })
	@Fetch(FetchMode.SUBSELECT)
	@OrderBy("sortOrder")
	public List<Resource> getResources() {
		return resources;
	}
	public void setResources(List<Resource> resources) {
		this.resources = resources;
	}
	@Column(name="role_name")
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	@Column(name="role_code")
	public String getCode() {
		return code;
	}
	public void setCode(String code) {
		this.code = code;
	}
	@Column(name="role_desc")
	public String getDesc() {
		return desc;
	}
	public void setDesc(String desc) {
		this.desc = desc;
	}
	@Column(name="role_status")
	public String getStatus() {
		return status;
	}
	public void setStatus(String status) {
		this.status = status;
	}
	public boolean equals(Object other){
		return EqualsBuilder.reflectionEquals(this, other);
	}
	public int hashCode(){
		return HashCodeBuilder.reflectionHashCode(this);
	}
	public String toString(){
		return ToStringBuilder.reflectionToString(this);
	}
}
